package com.yanqu.road.server.cmd.activity.operamask;

import com.yanqu.road.entity.activity.operamask.OperaMaskConfig;
import com.yanqu.road.entity.activity.operamask.OperaMaskUserData;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.OperaMaskProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.operamask.OperaMaskModule;
import com.yanqu.road.server.manger.activity.ActivityMgr;
import com.yanqu.road.server.manger.activity.operamask.OperaMaskMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_OPERA_MASK_CHECK_BLOCK, desc = "")
public class OperaMaskCheckBlockCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        OperaMaskConfig config = OperaMaskMgr.getConfig();
        if (config == null || !ActivityMgr.activityInTime(config.getActivityInfo())) {
            ret = GameErrorCode.E_ACTIVITY_NO_FOUND;
            return;
        }
        OperaMaskUserData userData = player.getModule(OperaMaskModule.class).getUserData();
        if (userData == null) {
            ret = GameErrorCode.E_OPERA_MASK_NO_UNLOCK;
            return;
        }

        ret = player.getModule(OperaMaskModule.class).checkBlock();
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            OperaMaskProto.OperaMaskCheckBlockRespMsg.Builder builder = OperaMaskProto.OperaMaskCheckBlockRespMsg.newBuilder();
            builder.setRet(0); // 失败了返回0，但是没有数据
            player.sendPacket(ClientProtocol.U_OPERA_MASK_CHECK_BLOCK, builder);
        }
    }
}
